package com.sky.zuor.manipulater;

import com.sky.result.Result;
import com.sky.zuor.LoginUtils;
import com.sky.zuor.ZuoruiLoginAndxingu;
import com.sky.zuor.ent.ZhuoRuiConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/zhuoruo/login")
@Slf4j
public class ZhuoRuiLoginManipulater {

    @Autowired
    private ZuoruiLoginAndxingu zuoruiLoginAndxingu;

    @GetMapping()
    public String test() throws Exception {
        zhuoRuoLogin();
        return ZhuoRuiConstant.token;
    }

    public void zhuoRuoLogin() throws Exception {
        long timestamp = System.currentTimeMillis();
        String loginEncrypted = LoginUtils.encrypt(ZhuoRuiConstant.TEST_ACCOUNT_LOGIN_PASSWORD, ZhuoRuiConstant.TEST_ACCOUNT_SECRETKEY, timestamp);
        String deviceId = String.valueOf(UUID.randomUUID());
        String deviceModel = "iPhone 14";
        String deviceName = "iPhone";
        String phoneArea = "86";
        ZuoruiLoginAndxingu.LoginResponse login = zuoruiLoginAndxingu.login(deviceId, deviceModel, deviceName, ZhuoRuiConstant.TEST_ACCOUNT_PHONE, phoneArea, loginEncrypted, timestamp);
        ZhuoRuiConstant.token = login.getData().getToken();
        String clientId = login.getData().getClientId();
        System.out.println(" ZhuoRuiConstant.token = " + ZhuoRuiConstant.token);
        String TrageEncrypted = LoginUtils.encrypt(ZhuoRuiConstant.TEST_ACCOUNT_TRADE_PASSWORD, ZhuoRuiConstant.TEST_ACCOUNT_SECRETKEY, timestamp);
        ZuoruiLoginAndxingu.ResponseData responseData = zuoruiLoginAndxingu.tradeLogin(clientId, TrageEncrypted, ZhuoRuiConstant.token);
        System.out.println("responseData = " + responseData);
    }
}